package com.lwy.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lwy.goods.dao.BrandMapper;
import com.lwy.goods.pojo.TbBrand;
import com.lwy.goods.service.BrandService;
import org.springframework.stereotype.Service;

import java.text.ParseException;

//品牌service接口实现类
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, TbBrand> implements BrandService {

//    品牌新增
    public int saveTbBrand(TbBrand tbBrand) throws ParseException {
        int insert = baseMapper.insert(tbBrand);
        return insert;
    }

//    品牌分页
    public PageInfo<TbBrand> page(String name,Integer pageNum, Integer pageSize){
        if(null==pageNum){
            //当前页
            pageNum=1;
        }
        if(null==pageSize){
            //一页多少数据
            pageSize=10;
        }
        QueryWrapper<TbBrand> wrapper = new QueryWrapper<>();
        //按品牌名称查询
        if(null!=name&&!"".equals(name)){
            wrapper.like("name",name);
        }
        //分页
        PageHelper.startPage(pageNum,pageSize);
        //将分页得到的数据封装成pageInfo对象
        PageInfo<TbBrand> pageInfo = new PageInfo<>(baseMapper.selectList(wrapper));
        //从pageInfo中获取list集合
//        List<TbBrand> list = pageInfo.getList();
        return pageInfo;
    }
}
